<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <meta charset="utf-8">
    <title>模板-添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" th:href="@{/layuiadmin/layui/css/layui.css}" href="../../../layuiadmin/layui/css/layui.css"
          media="all">
    <link rel="stylesheet" th:href="@{/css/layui-form-extend.css}">
    <link rel="stylesheet" th:href="@{/layuiadmin/modules/extends/dtree/dtree.css}">
    <link rel="stylesheet" th:href="@{/layuiadmin/modules/extends/dtree/font/dtreefont.css}">
</head>
<body>
<div style="padding: 50px;">
    <form th:id="lay-form" class="layui-form" lay-filter="lay-form" id="lay-form"
          th:action="@{/system/authority/edit/{authorityId}(authorityId=${authority.id})}" method="post">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label for="authorityName" class="layui-form-label lay-required">权限名称：</label>
                <div class="layui-input-inline">
                    <input type="text" id="authorityName" name="authorityName" class="layui-input lay-required" lay-verify="required"
                           placeholder="请输入" autocomplete="off" th:value="${authority.authorityName}">
                </div>
            </div>

            <div class="layui-inline">
                <label for="sort" class="layui-form-label lay-required">排序：</label>
                <div class="layui-input-inline">
                    <input type="text" id="sort" name="sort" class="layui-input lay-required" lay-verify="required"
                           placeholder=""
                           autocomplete="off" th:value="${authority.sort}">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="authorityNameEn" class="layui-form-label lay-required">识别码：</label>
            <div class="layui-input-block">
                <input type="text" id="authorityNameEn" name="authorityNameEn" class="layui-input lay-required" lay-verify="required"
                       placeholder="请输入" autocomplete="off" th:value="${authority.authorityNameEn}">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">系统资源：</label>
            <div class="layui-input-block">
                <input type="radio" name="sys" value="1" title="是" checked>
                <input type="radio" name="sys" value="0" title="否">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label lay-required">是否禁用：</label>
            <div class="layui-input-block">
                <input type="radio" name="deleted" value="1" title="是">
                <input type="radio" name="deleted" value="0" title="否" checked>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="authorityDesc" class="layui-form-label">授权描述：</label>
            <div class="layui-input-block">
                <textarea id="authorityDesc" name="authorityDesc" class="layui-textarea" th:text="${authority.authorityDesc}"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">菜单资源：</label>
            <div id="divTree" class="layui-col-md4" style="height: 800px;overflow: auto;">
                <ul id="resourceTree" class="dtree" data-id="0"></ul>
            </div>
        </div>

        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="lay-submit" id="lay-submit" value="确认">
        </div>

        <div>
            <input type="hidden" name="authorityId" id="authorityId" th:value="${authority.id}">
            <input type="hidden" name="hasResources" id="hasResources">
        </div>

    </form>
</div>
<script th:src="@{/layuiadmin/layui/layui.js}"></script>
<script th:inline="javascript">
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        dtree: 'modules/extends/dtree/dtree'
        //index: 'lib/index' //主入口模块
    }).use([ 'form', 'upload','dtree'], function () {
        var $ = layui.$
            , dtree = layui.dtree
            , form = layui.form
            , upload = layui.upload;

        // var dTreeResponse = [[${dTreeResponse}]];
        // console.log('dtreeData:' + JSON.stringify(dTreeResponse));
        // var dTreeData = [[${resources}]];
        // console.log("resources: + " + dTreeData);
        console.log(JSON.stringify([[${authority}]]));
        var resourceTree = dtree.render({
            elem: '#resourceTree',  //绑定元素
            request: {'nodeId':'1','authorityId':  $("#authorityId").val()},
            url: '/system/resource/getChildren',
            basicData: {'authorityId' : '1'},
            menubar:true,
            checkbar: true,
            checkbarType: "all",
            done:function(res, $obj, first){
                //dtree加载完毕后，展开全部节点
                resourceTree.menubarMethod().openAllNode($obj);
            }
        });

        dtree.on("node('resourceTree')",function(obj){
            //var params = dtree.getCheckbarNodesParam("checkbarTreea");
            if(!obj.param.leaf){
                var $div = obj.dom;
                resourceTree.clickSpread($div);  //调用内置函数展开节点
            } else {
                layer.msg("已经到底了");
            }
            //layer.msg(JSON.stringify(obj));
        });
        dtree.on("chooseDone('resourceTree')" ,function(obj){
            var params = dtree.getCheckbarNodesParam("resourceTree");
            params.length > 0 ? $("#hasResources").val(JSON.stringify(params)) : $("#hasResources").val('');
            //layer.msg(JSON.stringify(params));
            //console.log(obj.checkbarParams); // 选中的所有复选框的参数
        });
    })
</script>

<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/jquery.form.js}"></script>

<!--<script type="text/javascript" >-->
<!--    //jquery-form.js   ajax获取submit返回值-->
<!--    $(function () {-->
<!--        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引-->
<!--        /** 验证文件是否导入成功  */-->
<!--        $("#myForm").ajaxForm(function (data) {-->
<!--            if (data.code == 0) {-->
<!--                layer.msg("保存成功", {time: 1000}, function () {-->
<!--                    parent.layui.table.reload("layuiTable", {-->
<!--                        where: {time: new Date()}-->
<!--                    });-->
<!--                    parent.layer.close(index);-->
<!--                });-->
<!--            }-->
<!--        });-->
<!--    });-->
<!--</script>-->


</body>
</html>